﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using TweetSharp.Extensions;
using System.Windows.Markup;

namespace Halfwit.Converters
{
    public class TwitterDateTimeConverter : MarkupExtension, IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is DateTime)) return string.Empty;

            var d = (DateTime)value;

            var t = d.ToRelativeTime();
            if (t.ToLower() == "from the future")
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Future Tweet! {0} | {1}", d, DateTime.Now));
            }
            return t;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}
